// localStorage.BaseUrl = "http://ownerwork.mason101.cn:9521"
localStorage.BaseUrl = "http://127.0.0.1:9522"


// 检测邮箱
function checkEmail(str) {
    let re = /^[A-Za-z\d]+([-_.][A-Za-z\d]+)*@([A-Za-z\d]+[-.])+[A-Za-z\d]{2,4}$/
    // console.log(re.test(str))
    return re.test(str)
}

// 展示alert
function showAlert(i_alert, s_text, alert_type) {
    $("#alert_tip i").removeClass().addClass("fe mr-2 " + i_alert)
    $("#alert_tip span").text(s_text || "操作失败！")
    $("#alert_tip").removeClass().addClass("alert alert-icon " + alert_type).show().fadeOut(5000)
}

// 验证用户token是否过期
function checkUserToken(status, msg){
    if(status == 10010){
        showAlert("fe-alert-triangle", msg, "alert-danger")

        // 重置到登录页
        setTimeout(()=>{
            window.location.href = "./login.html"
        }, 2000);
    }
}

// 用户注销
function loginOut(){
    $.ajax(localStorage.BaseUrl + "/logout", {
        method: "POST",
        data: JSON.stringify({}),
        contentType: "application/json",
        dataType: "json",
        headers: {
            Authorization: localStorage.Token
        }
  
      }).done(function (data) {
        console.log(data)
      }).fail(function (xhr, status) {
        console.log(xhr)
        // showAlert("fe-alert-triangle", `服务器错误`, "alert-danger")
      }).always(() => {
        localStorage.clear()
        showAlert("fe-check", "用户退出成功。", "alert-success")
        setTimeout(()=>{
            window.location.href = "./login.html"
        }, 1000);
      })
}

function server_500(){
    showAlert("fe-alert-triangle", `服务器错误！`, "alert-danger")
    setTimeout(() => {
        location.href = "./500.html"
    }, 1000);
}
